<?php
session_start();
date_default_timezone_set("Asia/Chongqing");
include("../public/common.php");
include("../config/connect.php");

$userid = isset($_COOKIE["gwt_userid"]) ? $_COOKIE["gwt_userid"] : "";

$row = mysql_fetch_assoc(mysql_query("select password from user where id=$userid limit 1"));
$paw = $row["password"];
if($paw == "")
{
	$url = "Location:add_psw.php?id=".$userid."&ref=msg.php";
	header($url);
	exit;
}
else if(!HasLogin())
{
	$url = "Location:login.php?ref=msg.php";
	header($url);
	exit;
}

$id = isset($_COOKIE["gwt_userid"]) ? $_COOKIE["gwt_userid"] : "";
//$id = CheckUrlParamNoDie("id");	
//if ($id == "")
//{
	//echo "error";
	//exit;
//}

$opt = CheckUrlParamNoDie("opt");
$did = CheckUrlParamNoDie("did");
$nPage = CheckUrlParamNoDie("page");

if ($nPage == "") $nPage = 1;
if ($opt == "del" && $id != "")
{
	mysql_query("delete from gwt_msg where id=$did");
	if (mysql_affected_rows() == 1)
	{
		$url = "Location:msg.php?id=$id";
		header($url);
		exit;
	}
}

if($id != ""){
	$sql="update gwt_msg set see='1' where touser=".$id;
	mysql_query($sql);
}

$row = mysql_fetch_assoc(mysql_query("select count(*) as tmp from gwt_msg where touser=".$id));
$allCount = $row["tmp"];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>个人中心-积分消息动态</title>
<style type="text/css">
body {font-size: 12px;color: #000;font-family: 宋体;}
.STYLE1 {font-size: 13px;font-weight: bold;}
table {border-collapse:collapse; border-spacing:2px;  font-size:12px;}
td,th { display:table-cell; vertical-align:inherit;}
img { border:0; vertical-align:top;}
.myTable td { background:#FFF;}
#pageNav { margin:20px auto; text-align:center; width:100%;}
#pageNav a,#pageNav b { background-color:#F4D662; border:1px solid #7d2b00; color:#fff; display:inline-block; font-size:12px; height:22px; line-height:22px; margin:0 1px; min-width:12px; padding:0 4px; white-space:nowrap; text-align:center;}
#pageNav a { color:#7d2b00; background-color:#FFF;}
#pageNav a:hover {background-color:#F4D662;color:#fff;}

</style>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="920" border="1" cellpadding="0" cellspacing="0" align="center" bordercolor="#a8a8a8">
	<tr>
    	<td>
			<table width="920" height="102" border="0" align="center" cellpadding="0" cellspacing="0" background="images/bar_bg.gif" >
            	<tr>
                    <td width="230" valign="top">&nbsp;</td>
                    <td width="275" valign="top"><img src="images/bar_left_bg.gif" width="107" height="81" /></td>
                    <td width="415" valign="top"><img src="images/user_n.gif" width="407" height="102" /></td>
            	</tr>
			</table>
  		</td>
	</tr>
    <tr>
    	<td>
        <table cellspacing="1" cellpadding="2" border="0" style="background:#a8a8a8;border-collapse: separate; border-spacing: 1px;" align="center" width="100%" class="myTable">
        	<tr>
            	<td colspan="4" height="40" align="center" style="background:#F4D662;font-size:14px;"><b style="color:#FFF;">积分消息动态</b>（<font color="#FF0000"
                ;><?php echo $allCount; ?></font>）</td>
            </tr>
            <?php
            	if($allCount == '0' || $allCount == ''){
					echo '<tr><td  align="center" height="100">暂时没有消息~~</td></tr>';	
				}else{
			?>
            <?php
				$PAGE_SIZE = 10; //每页数量
            	$limit = " limit ". ($nPage-1)*$PAGE_SIZE .",$PAGE_SIZE";
				
            	$sql = "select * from gwt_msg where touser=$id order by id desc".$limit;
				$result = mysql_query( $sql );
				$i = 0;
				while( $result && $row = mysql_fetch_assoc( $result ))
				{
            ?>
            <tr>
                <td height="40" width="100" align="center">系统消息</td>
                <td><?php echo $row["content"]; ?></td>
                <td width="100" align="center"><?PHP echo $row["time"] ?></td>
                <td align="center"><a href='?id=<?php echo $id; ?>&opt=del&did=<?php echo $row["id"]; ?>&page=<?php echo $nPage; ?>'>删除</a></td>
            </tr>
            <?php } ?>
            <?PHP if ($allCount > $PAGE_SIZE) { ?>
            <tr>
            	<td colspan="4">
                <div id="pageNav">                        
                        <?php	
						$all_page = ceil($allCount / $PAGE_SIZE);
						if ($nPage > 1) echo "<a class='pageNext' href='?page=".($nPage-1)."&id=$id'>上一页</a>";
						
						if($all_page<=12){				
							for($i=1;$i<=$all_page;$i++){//数字分页
								$Pageshow = ($i!=$nPage)?"<a href='?page=$i&id=$id'>".($i)."</a>":"<b>".($i)."</b>";
								echo $Pageshow;
						  	}
						}else{
							for($i=1;$i<=12;$i++){//数字分页
								$Pageshow = ($i!=$nPage)?"<a href='?page=$i&id=$id'>".($i)."</a>":"<b>".($i)."</b>";
								echo $Pageshow;
						  	}
						}
						
						if($nPage == 12 || $nPage == $all_page){
							echo "";
						}else if($nPage < 12){
							echo "<a class='pageNext' href='?page=".($nPage+1)."&id=$id'>下一页</a>";
						}
						 ?>
            		</div>
                </td>
            </tr>
            <?php } } ?>
        </table>
        </td>
    </tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" width="920" align="center">
    <tr>
        <td width="537" height="30" style="padding-left:5px; font-size:12px; color:#666">冰峰科技旗下购物兔 CopyRight 2011 gouwutu.com 粤ICP备11009208号</td>
        <td width="241"><span style="font-size:12px; color:#666">在线QQ客服：<a href="http://wpa.qq.com/msgrd?v=3&amp;uin=1753949757&amp;site=qq&amp;menu=yes" target="_blank"><img align="absmiddle" title="欢迎点击和我们交流" src="http://wpa.qq.com/pa?p=2:1753949757:42" border="0" alt="点击和我们交流" /></a>&nbsp;&nbsp;&nbsp;</span></td>
        <td width="142" height="30" align="right" style="font-size:12px; color:#666"><a href="mailto:admin@gouwutu.com" target="_blank" style="font-size:12px; color:#666; font-weight:400; text-decoration:underline">联系我们</a>&nbsp;&nbsp;&nbsp;&nbsp;</td>
    </tr>
</table>
</body>
</html>